//
//  QNavigationVC.m
//  QoilPublic
//
//  Created by 杨凯 16/7/25.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QNavigationVC.h"
#import "AAAVC.h"
#import "QPaySuccessVC.h"
#import "QPayOrderSuccessVC.h"
#import "QForgetPayPassWordVC.h"
#import "QDTSuccessVC.h"
#import "QDetailsOrderVC.h"
@interface QNavigationVC ()<UIGestureRecognizerDelegate>

@end

@implementation QNavigationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UINavigationBar *bar=[UINavigationBar appearance];
    bar.barTintColor = [QColorUtility defaultBlueColor];
    bar.translucent = YES;
    [bar setTitleTextAttributes:@{
                                  NSForegroundColorAttributeName:[UIColor whiteColor],
                                  NSFontAttributeName:[UIFont systemFontOfSize:Ksize18]
                                  }];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//设置状态栏
        // 全屏滑动返回
    id target = self.interactivePopGestureRecognizer.delegate;

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    
    
    self.interactivePopGestureRecognizer.enabled = YES;
}

- (void)handleNavigationTransition:(UIPanGestureRecognizer *)pan{
   
    [self popViewControllerAnimated:YES];

}

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{

    if (self.childViewControllers.count <= 1){
        return NO;
    }
    
    if ([[self valueForKey:@"_isTransitioning"] boolValue]) {
        return NO;
    }
    
    CGPoint translation = [gestureRecognizer translationInView:gestureRecognizer.view];
    if (translation.x <= 0) {
        return NO;
    }
    
    if([self.visibleViewController isKindOfClass:[QPaySuccessVC class]]){
        return NO;
    }
    
    if([self.visibleViewController isKindOfClass:[QPayOrderSuccessVC class]]){
        return NO;
    }
    
    if([self.visibleViewController isKindOfClass:[QForgetPayPassWordVC class]]){
        return NO;
    }
    
    if([self.visibleViewController isKindOfClass:[QDTSuccessVC class]]){
        return NO;
    }
    

    return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    // 首先判断otherGestureRecognizer是不是系统pop手势
     UIScrollView *scrollView = (UIScrollView *)otherGestureRecognizer.view;
    if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UIScrollView")]) {
        if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && scrollView.contentOffset.x == 0) {
            return YES;
        }
    }
    return NO;
}
//导航控制器里面
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count == 0) {
//        self.navigationBar.backgroundColor = [UIColor colorWithRed:0.345 green:0.624 blue:0.961 alpha:1];
//        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:nil image:@"nav_home_logo" highLightImage:nil];;
//        //扫码
//        viewController.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(search) image:@"nav_home_sao" highLightImage:@"nav_home_sao"];
        
    }
    if (self.viewControllers.count > 0) {
//        viewController.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"nav_back" highLightImage:@"nav_back"];
        viewController.hidesBottomBarWhenPushed=YES;
    }
    
    [super pushViewController:viewController animated:YES];
    
}

@end
